<?php
/**
 * Created by PhpStorm.
 * User: kkw
 * Date: 2019/1/30
 * Time: 22:14
 */
namespace kkw\goods\response;
use kkw\user\Util;
use kkw\goods\table\GoodsTable;
use suda\core\Request;
use suda\core\Response;

class DeleteGoodsResponse extends  Response
{
    public function onRequest(Request $request)
    {
        Util::printHeader();
        $json = Request::json();
        $id= $json['id'];
        $goods = new GoodsTable();
        try {
            $goods->delete([id=>$id]);
        } catch (\suda\exception\SQLException $e) {
            $this->json(['code'=>$e->getCode(),'message'=> '删除数据失败']);
        }
        $this->json(['code'=>0,'message'=>'删除数据成功']);
    }
}